//
//  HELSigninDetailVC.m
//  sanda
//
//  Created by 陈武琦 on 16/9/23.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELSigninDetailVC.h"
#import <Masonry.h>
#import "HELSigninCourseModel.h"
#import "NSString+Utilities.h"
#import "NSDate+Category.h"

@interface HELSigninDetailVC ()

//用户签到
@property (weak, nonatomic) IBOutlet UIView *headView;
//签到时间
@property (weak, nonatomic) IBOutlet UILabel *signinTime;
//签到地点
@property (weak, nonatomic) IBOutlet UILabel *signinLocation;
//课程标题
@property (weak, nonatomic) IBOutlet UILabel *coursetTitle;
@property (weak, nonatomic) IBOutlet UILabel *teacherLabel;
//授课老师
@property (weak, nonatomic) IBOutlet UILabel *teacher;
//上课地点
@property (weak, nonatomic) IBOutlet UILabel *classPlace;
//开课日期
@property (weak, nonatomic) IBOutlet UILabel *registerCouseDate;
//开课时间
@property (weak, nonatomic) IBOutlet UILabel *registerCouseTime;
//签到日期范围
@property (weak, nonatomic) IBOutlet UILabel *standadSigninDate;
//签到时间范围
@property (weak, nonatomic) IBOutlet UILabel *standadSignTime;
//主办单位
@property (weak, nonatomic) IBOutlet UILabel *organizer;
@property (weak, nonatomic) IBOutlet UILabel *certificateTypeLabel;
//证书类型
@property (weak, nonatomic) IBOutlet UILabel *certificateType;
//联系人
@property (weak, nonatomic) IBOutlet UILabel *contactPeople;
//电话
@property (weak, nonatomic) IBOutlet UILabel *phone;
//课程内容
@property (weak, nonatomic) IBOutlet UILabel *couserContent;
@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (weak, nonatomic) IBOutlet UIImageView *haveSigninedImageVIew;

@property(nonatomic, strong)HELSigninCourseModel *model;

@end

@implementation HELSigninDetailVC

- (instancetype)initWithModel:(HELSigninCourseModel *)model {
    if (self = [super init]) {
        _model = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleView:@"签到详情"];
    [self setupWithModel:self.model];
       // Do any additional setup after loading the view from its nib.
}

- (void)setupWithModel:(HELSigninCourseModel *)model {
    
    if (![self.model.signType isEqualToString:@"yesSign"]) {
        self.haveSigninedImageVIew.hidden = YES;
        [self.headView removeFromSuperview];
        [self.view2 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.scrollview.mas_top);
        }];
    }else {
        self.haveSigninedImageVIew.hidden = NO;
        self.signinTime.text = model.signTimeShow;
        self.signinLocation.text = model.signAddress;
    }
        
    self.registerCouseDate.text = [NSString timeStringMMDDHMFrom:[model.courseStart longLongValue]];
    self.registerCouseTime.text = [NSString timeStringMMDDHMFrom:[model.courseEnd longLongValue]];
    self.standadSigninDate.text = [NSString timeStringMMDDHMFrom:[model.signStart longLongValue]];
    self.standadSignTime.text = [NSString timeStringMMDDHMFrom:[model.signEnd longLongValue]];
    
    self.coursetTitle.text = model.courseName;
    [self setTeacherNameText:model.teacher];
    self.classPlace.text = model.holdPlace;
    self.organizer.text = model.courseHospitalName;
    [self setCertificateTypeText:model.certificateType];
    self.contactPeople.text = model.contacts;
    self.phone.text = model.contactsPhone;
    self.couserContent.text = model.courseDesc;

}

- (void)setTeacherNameText:(NSString *)name {
    
    if ([name isEmpty] || name == nil) {
        self.teacherLabel.hidden = YES;
        self.teacher.hidden = YES;
        [self.teacherLabel removeFromSuperview];
        [self.teacher removeFromSuperview];
        [self.classPlace mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.coursetTitle.mas_bottom).offset(12);
        }];
    }else {
        self.teacher.text = name;
    }
}

- (void)setCertificateTypeText:(NSString *)text {
    
    if ([text isEmpty] || text == nil) {
        self.certificateTypeLabel.hidden = YES;
        self.certificateType.hidden = YES;
        [self.certificateTypeLabel removeFromSuperview];
        [self.certificateType removeFromSuperview];
        [self.phone mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.organizer.mas_bottom).offset(12);
        }];
    }else {
        self.certificateType.text = text;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
